package com.negative.logic;

import com.negative.activities.InfoActivity;
import com.negative.activities.MainMenu;
import com.negative.activities.PurchaseListActivity;
import com.negative.activities.R;
import com.negative.activities.SettingsActivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.MenuItem;
import android.widget.PopupMenu.OnMenuItemClickListener;

public class MenuItemListener implements OnMenuItemClickListener{

	Intent intent;
	Context context;
	
	public MenuItemListener(Context context) {
		this.context = context;
	}
	
	@Override
	public boolean onMenuItemClick(MenuItem item) {
		
		Activity activity = (Activity) context;
		
		switch (item.getItemId()) {
		case R.id.home_item:
			if (activity instanceof MainMenu) {
				return false;
			}
			intent = new Intent(context, MainMenu.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			context.startActivity(intent);
			break;
		case R.id.settings_item:
			if (activity instanceof SettingsActivity) {
				return false;
			}
			intent = new Intent(context, SettingsActivity.class);
			context.startActivity(intent);
			break;
		case R.id.info_item:
//			if (activity instanceof InfoActivity) {
//				return false;
//			}
//			intent = new Intent(context, InfoActivity.class);
//			context.startActivity(intent);
			Thread dialogThread = new Thread() {
				public void run() {
					DialogManager.showOKDialog((Activity)context, false, context.getString(R.string.sorry), context.getString(R.string.inactive));
				}
			};
			dialogThread.start();
			break;
		case R.id.my_purchases_item:
			if (activity instanceof PurchaseListActivity) {
				return false;
			}
			intent = new Intent(context, PurchaseListActivity.class);
			context.startActivity(intent);
			break;
		}
		return true;
	}

}
